#include "loc_correction/math_utils.h"
#include <cmath>

namespace MathUtils
{
    double calculate_variance(const std::vector<double>& data){
        double sum = 0;
        double mean = 0;
        double variance = 0;

        if (data.size() > 1){
            for (auto value : data){
                sum += value;
            }

            mean = sum / data.size();

            for (auto value : data){
                variance += (value - mean) * (value - mean);
            }

            variance /= (data.size() - 1);
        }

        return variance;
    }
}